using UnityEngine;
using UnityEditor;

namespace Runtime.Module.GameGraphic.Editor
{
    [CustomEditor(typeof(RectTransform))]
    public class CustomRectTransformEditor : IsScriptCtrlEditor<RectTransform>
    {
        private UnityEditor.Editor defaultEditor;

        protected override void OnEnable()
        {
            base.OnEnable();
            // Get the internal RectTransformEditor type
            var editorAssembly = typeof(UnityEditor.Editor).Assembly;
            var rectTransformEditorType = editorAssembly.GetType("UnityEditor.RectTransformEditor");

            // Create an instance of the internal RectTransformEditor
            defaultEditor = CreateEditor(target, rectTransformEditorType);
        }

        protected override void OnDisable()
        {
            base.OnDisable();
            // Destroy the instance of the internal RectTransformEditor
            if (defaultEditor != null)
            {
                DestroyImmediate(defaultEditor);
            }
        }

        public override void OnInspectorGUI()
        {
            OnInspectorGUIOfScript();
            if (defaultEditor != null)
            {
                defaultEditor.OnInspectorGUI();
            }
        }
    }
}